//
//  ViewController.m
//  ADemo
//
//  Created by 陈超 on 2021/7/13.
//

#import "ViewController.h"
#import "fishhook.h"
#include <mach-o/dyld.h>
@interface ViewController ()

@end

@implementation ViewController
static id _self;
- (void)viewDidLoad {
    [super viewDidLoad];
//    NSLog(@"123");
    //定义rebinding结构体
    struct rebinding nslogBind;
    //函数的名称
    nslogBind.name = "NSLog";
    //新的函数地址
    nslogBind.replacement = myNSLog;
    //保存原始函数地址的变量的指针
    nslogBind.replaced = (void *)&old_nslog;
    
    //定义数组
    struct rebinding rebs[] = {nslogBind};
    /*
     arg1 : 存放rebinding结构体的数组
     arg2 : 数组的长度
     */
    rebind_symbols(rebs, 1);
    _self = self;
//    _dyld_register_func_for_add_image(_rebind_symbols_for_image);
}

//函数指针,用来保存原始的函数的地址
static void (*old_nslog)(NSString *format, ...);

//新的NSLog
void myNSLog(NSString *format, ...){
    format = [format stringByAppendingString:@"\n勾上了!"];
    //再调用原来的
    old_nslog(format);
    
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"点击了屏幕!!");
    
}
@end
